<template>
	<jn-page>
		<view class="wrap">
			<view class="u-tabs-box">
				<u-tabs activeColor="#f29100" :list="list" :is-scroll="false" :current="current" @change="change"></u-tabs>
			</view>
			
			<view class="">
				<view class="page-box" v-if="orderLists != '' ">
					<view class="order" v-for="(res, index) in orderLists" :key="res.id">
						<view class="top">
							<view class="left">
								<u-icon name="home" :size="30" color="rgb(94,94,94)"></u-icon>
								
								<view class="store" v-if=" res.ordertype == 'mt' ">【美团】{{ res.smstitle }}</view>
								<view class="store" v-if=" res.ordertype == 'ele' ">【饿了么】{{ res.smstitle }}</view>
								
								<u-icon name="arrow-right" color="rgb(203,203,203)" :size="26"></u-icon>
							</view>
							<view class="right" v-if="res.status == '1' ">待结算</view>
							<view class="right" v-if="res.status == '2' ">已结算</view>
						</view>
						<view class="item">
							<view class="left"></view>
							<view class="content">
								<view class="title u-line-2">订单编号：{{ res.order_id }}</view>
								<view class="more" v-if="res.from_id == '0' ">订单所属：自己</view>
								<view class="more" v-if="res.from_id != '0' ">订单所属：下级</view>
							</view>
							
						</view>
						<view class="total">
							订单金额:
							<text class="total-price">
								￥
								<text class="decimal">{{res.payprice}}</text>
							</text>
						</view>
						<view class="total">
							合计收益:
							<text class="total-price">
								￥
								<text class="decimal">{{res.user_profit}}</text>
							</text>
						</view>
					</view>
					<u-loadmore :status="loadStatus" bgColor="#f2f2f2"></u-loadmore>
				</view>
				<view class="page-box" v-if="orderLists == '' ">
					<view>
						<view class="centre">
							<u-empty text="您还没有相关的订单" mode="order"></u-empty>
						</view>
					</view>
				</view>
			</view>
		</view>
	</jn-page>
</template>

<script>
	export default {
		data() {
			return {
				orderLists:[],
				list: [
					{
						name: '全部订单'
					},
					{
						name: '待结算'
					},
					{
						name: '已结算'
					}
				],
				current: 0,
				loadStatus: 'loadmore',
				page: 1,
				total:0,
			}
		},
		onLoad(e) {
			this.current = e.current;
			this.getorder(this.current, 1)
			
		},
		computed: {
			
		},
		methods: {
			
			getorder(type, page) {  //0（所有）   1（待结算）   2（已完成）
				this.$u.post('/wxapi/api/get_order', {
					token: this.vuex_token.accessToken,
					'type': type,
					'page': page
					//serinfo:this.vuex_user.userinfo
				}).then(res => {
					console.log(res);
					if (res.code == 200) {
						this.page = res.data.allpage
						this.total = res.data.total
						
						for(var child of res.data.datalist)
						{
								this.orderLists.push(child);
						}
						
						//this.orderLists = res.data.datalist
						
						
						
					} else if (res.code == 999) {
			
					}
					return false;
				});
			},
			
			// tab栏切换
			change(index) {
				this.current = index;
				this.orderLists=[];
				this.page= '1';
				this.getorder(index, this.page);
				
				
			},
			onReachBottom() {
				if(this.total >= 12){
					this.loadStatus = 'loading';
					this.page = ++ this.page;
					setTimeout(() => {
						
						this.getorder(this.current, this.page);
						if(this.page >= 3) this.status = 'nomore';
						else this.status = 'loading';
					}, 500)
				}else{
					this.loadStatus = 'nomore';
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
.order {
	width: 710rpx;
	background-color: #ffffff;
	margin: 20rpx auto;
	border-radius: 20rpx;
	box-sizing: border-box;
	padding: 20rpx;
	font-size: 28rpx;
	.top {
		display: flex;
		justify-content: space-between;
		.left {
			display: flex;
			align-items: center;
			width: 80%;
			.store {
				margin: 0 10rpx;
				font-size: 32rpx;
				font-weight: bold;
				display: inline-block;
				white-space: nowrap;
				overflow: hidden;
				text-overflow:ellipsis;
			}
		}
		.right {
			color: $u-type-warning-dark;
			display: flex;
			flex: none;
		}
	}
	.item {
		display: flex;
		margin: 20rpx 0 0;
		.left {
			margin-right: 20rpx;
			image {
				width: 200rpx;
				height: 200rpx;
				border-radius: 10rpx;
			}
		}
		.content {
			.title {
				font-size: 28rpx;
				line-height: 50rpx;
			}
			.type {
				margin: 10rpx 0;
				font-size: 24rpx;
				color: $u-tips-color;
			}
			.delivery-time {
				color: #e5d001;
				font-size: 24rpx;
			}
			.decimal {
				font-size: 24rpx;
				margin-top: 4rpx;
			}
		}
	}
	.total {
		margin-top: 20rpx;
		text-align: right;
		font-size: 24rpx;
		.total-price {
			font-size: 32rpx;
		}
	}
	.bottom {
		display: flex;
		margin-top: 40rpx;
		padding: 0 10rpx;
		justify-content: space-between;
		align-items: center;
		.btn {
			line-height: 52rpx;
			width: 160rpx;
			border-radius: 26rpx;
			border: 2rpx solid $u-border-color;
			font-size: 26rpx;
			text-align: center;
			color: $u-type-info-dark;
		}
		.evaluate {
			color: $u-type-warning-dark;
			border-color: $u-type-warning-dark;
		}
	}
}
.centre {
	text-align: center;
	margin: 200rpx auto;
	font-size: 32rpx;
	image {
		width: 164rpx;
		height: 164rpx;
		border-radius: 50%;
		margin-bottom: 20rpx;
	}
	.tips {
		font-size: 24rpx;
		color: #999999;
		margin-top: 20rpx;
	}
	.btn {
		margin: 80rpx auto;
		width: 200rpx;
		border-radius: 32rpx;
		line-height: 64rpx;
		color: #ffffff;
		font-size: 26rpx;
		background: linear-gradient(270deg, rgba(249, 116, 90, 1) 0%, rgba(255, 158, 1, 1) 100%);
	}
}
.wrap {
	display: flex;
	flex-direction: column;
	height: calc(100vh - var(--window-top));
	width: 100%;
}
.swiper-box {
	flex: 1;
}
.swiper-item {
	height: 100%;
}
</style>
